<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 */
class Application_Model_Ordre extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(2)
     *
     * @var int
     */
    protected $_ParcoursIdParcours;

    /**
     * Database var type int(100)
     *
     * @var int
     */
    protected $_FormationIdFor;

    /**
     * Database var type int(10)
     *
     * @var int
     */
    protected $_Numformation;


    /**
     * Parent relation fk_parcours_has_formation_formation1
     *
     * @var Application_Model_Formation
     */
    protected $_Formation;

    /**
     * Parent relation fk_parcours_has_formation_parcours1
     *
     * @var Application_Model_Parcours
     */
    protected $_Parcours;


    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'parcours_id_parcours'=>'ParcoursIdParcours',
            'formation_id_for'=>'FormationIdFor',
            'numformation'=>'Numformation',
        ));

        $this->setParentList(array(
            'FkParcoursHasFormationFormation1'=> array(
                    'property' => 'Formation',
                    'table_name' => 'Formation',
                ),
            'FkParcoursHasFormationParcours1'=> array(
                    'property' => 'Parcours',
                    'table_name' => 'Parcours',
                ),
        ));

        $this->setDependentList(array(
        ));
    }

    /**
     * Sets column parcours_id_parcours
     *
     * @param int $data
     * @return Application_Model_Ordre
     */
    public function setParcoursIdParcours($data)
    {
        $this->_ParcoursIdParcours = $data;
        return $this;
    }

    /**
     * Gets column parcours_id_parcours
     *
     * @return int
     */
    public function getParcoursIdParcours()
    {
        return $this->_ParcoursIdParcours;
    }

    /**
     * Sets column formation_id_for
     *
     * @param int $data
     * @return Application_Model_Ordre
     */
    public function setFormationIdFor($data)
    {
        $this->_FormationIdFor = $data;
        return $this;
    }

    /**
     * Gets column formation_id_for
     *
     * @return int
     */
    public function getFormationIdFor()
    {
        return $this->_FormationIdFor;
    }

    /**
     * Sets column numformation
     *
     * @param int $data
     * @return Application_Model_Ordre
     */
    public function setNumformation($data)
    {
        $this->_Numformation = $data;
        return $this;
    }

    /**
     * Gets column numformation
     *
     * @return int
     */
    public function getNumformation()
    {
        return $this->_Numformation;
    }

    /**
     * Sets parent relation FormationIdFor
     *
     * @param Application_Model_Formation $data
     * @return Application_Model_Ordre
     */
    public function setFormation(Application_Model_Formation $data)
    {
        $this->_Formation = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['id_for'];
        }

        $this->setFormationIdFor($primary_key);

        return $this;
    }

    /**
     * Gets parent FormationIdFor
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Formation
     */
    public function getFormation($load = true)
    {
        if ($this->_Formation === null && $load) {
            $this->getMapper()->loadRelated('FkParcoursHasFormationFormation1', $this);
        }

        return $this->_Formation;
    }

    /**
     * Sets parent relation ParcoursIdParcours
     *
     * @param Application_Model_Parcours $data
     * @return Application_Model_Ordre
     */
    public function setParcours(Application_Model_Parcours $data)
    {
        $this->_Parcours = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['id_parcours'];
        }

        $this->setParcoursIdParcours($primary_key);

        return $this;
    }

    /**
     * Gets parent ParcoursIdParcours
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Parcours
     */
    public function getParcours($load = true)
    {
        if ($this->_Parcours === null && $load) {
            $this->getMapper()->loadRelated('FkParcoursHasFormationParcours1', $this);
        }

        return $this->_Parcours;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_Ordre
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_Ordre());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_Ordre::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        $primary_key = array();
        if (! $this->getParcoursIdParcours()) {
            throw new Exception('Primary Key ParcoursIdParcours does not contain a value');
        } else {
            $primary_key['parcours_id_parcours'] = $this->getParcoursIdParcours();
        }

        if (! $this->getFormationIdFor()) {
            throw new Exception('Primary Key FormationIdFor does not contain a value');
        } else {
            $primary_key['formation_id_for'] = $this->getFormationIdFor();
        }

        return $this->getMapper()->getDbTable()->delete('parcours_id_parcours = '
                    . $this->getMapper()->getDbTable()->getAdapter()->quote($primary_key['parcours_id_parcours'])
                    . ' AND formation_id_for = '
                    . $this->getMapper()->getDbTable()->getAdapter()->quote($primary_key['formation_id_for']));
    }
}
